package com.freewater.parking.infrastructure.event;

import com.freewater.parking.domain.common.DomainEvent;
import com.freewater.parking.domain.common.DomainEventListener;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class SyncDomainEventDispatcher implements DomainEventDispatcher {

    private final List<DomainEventListener> eventListeners;

    public SyncDomainEventDispatcher(List<DomainEventListener> eventListeners) {
        this.eventListeners = eventListeners == null ? new ArrayList<>() : eventListeners;
    }

    @Override
    public void dispatch(DomainEvent event) {
        for (DomainEventListener eventListener : eventListeners) {
            eventListener.onEvent(event);
        }
    }
}
